﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using AbpVueDemo.SystemBase.DictionaryTableManager.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AbpVueDemo.SystemBase.DictionaryTableManager;
using Abp.Application.Services.Dto;
using Abp.Linq.Extensions;

namespace AbpVueDemo.SystemBase.DictionaryTableManager
{
    /// <summary>
    /// 字典表接口的实现     lzh
    /// 第一个参数 字典表持久模型, 表示操作数据库用model
    ///   DictionaryTableDto 表示字典表的数据传输对象 
    ///   int 表示操作数据类的主键类型
    ///  PageDictionaryTableRequestDto 分页请求对象 
    ///  DictionaryTableCreateDto 字典创建对象 
    ///  DictionaryTableUpdateDto 字典修改对象 
    /// </summary>
    public class DictionaryTableService: AsyncCrudAppService<DictionaryTable,DictionaryTableInputDto, int, PageDictionaryTableRequestDto, DictionaryTableCreateDto, DictionaryTableUpdateDto>, IDictionaryTableService
    {
        public DictionaryTableService(
          IRepository<DictionaryTable, int> repository) : base(repository)
        {
           
        }

        /// <summary>
        /// 自定义分页条件查询, 需要重写父类的CreateFilteredQuery方法,让其进行自定义条件筛选
        /// </summary>
        /// <param name="input">查询条件</param>
        /// <returns></returns>
        protected override IQueryable<DictionaryTable> CreateFilteredQuery(PageDictionaryTableRequestDto input)
        {
            return Repository.GetAllIncluding(c=>c.DictionaryTypeTable)
                .WhereIf(!string.IsNullOrEmpty(input.dt_key), c => c.dt_key.Contains(input.dt_key))
                 .WhereIf(!string.IsNullOrEmpty(input.dt_type_key), c => c.dt_type_key.Equals(input.dt_type_key))
                .WhereIf(!string.IsNullOrEmpty(input.dt_name), c => c.dt_name.Contains(input.dt_name))
                 .WhereIf(input.dt_status.HasValue, c => c.dt_status == input.dt_status);
        }



    }
}
